Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Solving systems of linear equations*Ax = B*for*x

    Dear all,
    I wonder if there is any straightforward solution for solving systems of linear equations Ax = B for x? In MATLAB this is done through the mldivide() function. It's as easy as writing x = A\B - further information on Matlab function is available here: Solve systems of linear equations Ax = B for x - MATLAB mldivide \ - MathWorks Australia.
    Best regards,
    Eilya.

  • #2
    Code:
    help [M-4] solvers
    will give you a good overview

    Comment


    • #3
      I found the following blog posts to be very illuminating:

      https://www.johndcook.com/blog/2010/...t-that-matrix/

      https://gregorygundersen.com/blog/20...rix-inversion/

      if you go to the Matlab documentation, the flowchart is quite helpful: https://www.mathworks.com/help/matla...html#bt4jslc-6

      There is essentially an equivalent set of solvers in Stata that can be implemented directly. If you are on Stata 17 or greater, and you are on an Intel machine, you should absolutely use the LAPACK versions of the solvers where available. They target the LAPACK/BLAS implementation in the Intel MKL, and there is some serious dark magic going on with that thing.

      I’ve occasionally found that it can also be useful to take the advice from the blog posts and perform the decompositions first and then apply the triangular solver separately when you need to do several solves with the same matrix.
      Last edited by Malcolm Wardlaw; 23 Oct 2023, 01:21.

      Comment


      • #4
        In addition to solvers, you can write:
        Code:
        x = pinv(A)*B
        The solution always exists, provided the SVD can compute the pseudoinverse
        For (over)determined systems, it is equivalent to OLS, and for underdetermined ones, it is the minimum-norm general least squares solution.
        Last edited by Ilya Bolotov; 19 Feb 2024, 17:04.

        Comment

        Working...
        X